﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 设计模式
{
    class work_do {
        public static void main() {
            work w = new work();
            w.hour = 9;
            w.write_program();
            w.hour = 10;
            w.write_program();
            w.hour = 13;
            w.write_program();
            w.hour = 14;
            w.write_program();
            w.hour = 17;
            w.write_program();

            w.tast_finish = false;

            w.hour = 19;
            w.write_program();
            w.hour = 22;
            w.write_program();

        }
    }
    
    public class work
    {
        private state current;
        public work() {
            current = new forenoon_state();
        }


        public double hour;

        public bool tast_finish;


        public void setstate(state s) {
            current = s;
        }

        public void write_program() {

            current.write_program(this);
        
        }

    }

    public abstract class state {
        public abstract void write_program(work w);
    }

    public class forenoon_state : state
    {
        public override void write_program(work w)
        {
            if (w.hour < 12)
            {
                Console.WriteLine("当前时间：{0}点 上午工作，精神百倍", w.hour);
            }
            else {
                w.setstate(new noon_state());
                w.write_program();
            }
        }
    }

    public class noon_state : state {
        public override void write_program(work w)
        {
            if (w.hour < 13)
            {
                Console.WriteLine("当前时间：{0}点 午饭 犯困 午休", w.hour);

            }
            else {
                w.setstate(new afternoon_state());
                w.write_program();
            }
        }
    }

    public class afternoon_state : state
    {
        public override void write_program(work w)
        {
            if (w.hour < 17)
            {
                Console.WriteLine("当前时间：{0}点 快下班了 还不错", w.hour);

            }
            else
            {
                w.setstate(new evening_state());
                w.write_program();
            }
        }
    }


    public class evening_state : state
    {
        public override void write_program(work w)
        {
            if(w.tast_finish){
                w.setstate(new rest_state());
                w.write_program();
            }
            
            if (w.hour < 21)
            {
                Console.WriteLine("当前时间：{0}点 加班 疲惫之极", w.hour);

            }
            else
            {
                w.setstate(new sleep_state());
                w.write_program();
            }
        }
    }

    public class sleep_state : state
    {
        public override void write_program(work w)
        {
          
                Console.WriteLine("当前时间：{0}点 不行了 睡着了", w.hour);

           
        }
    }

    public class rest_state : state
    {
        public override void write_program(work w)
        {

            Console.WriteLine("当前时间：{0}点 下班回家了", w.hour);


        }
    }


}
